package dbinfo;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import db.DbConnectionFactory;
import db.DbConnectionFactoryImpl;
			   

public class DbInfoDao {
	private Connection con;
	
	public DbInfoDao(){
		DbConnectionFactory dbConnectionFactory = new DbConnectionFactoryImpl();
		con = dbConnectionFactory.getConnection();
	}

	//메타정보 조회
	public DatabaseMetaData getDbMetaInfo() {
		DatabaseMetaData dbMeta = null; 
		try {
			dbMeta = con.getMetaData();			
		} catch (SQLException e) {
			e.printStackTrace();
			dbMeta = null;
		}
		return dbMeta;
	}

	//데이터베이스정보조회
	public List<Map<String,String>> getDbInfo() {
		ResultSet rs;
		List<Map<String,String>> resultList = new ArrayList<Map<String,String>>();
		StringBuffer query = new StringBuffer();
		query.append(" select * from v$database ");
		
		try {
			PreparedStatement pstm = con.prepareStatement(query.toString());
			rs = pstm.executeQuery();
			ResultSetMetaData rsmd = rs.getMetaData();
			int numberOfColumn = rsmd.getColumnCount();
			
			while(rs.next()){
				for(int i = 1; i <= numberOfColumn; i++){
					HashMap<String, String> resultMap = new HashMap<String, String>();
					resultMap.put(rsmd.getColumnName(i), rs.getString(i));
					resultList.add(resultMap);
				}
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return resultList;
	}
}